package com.disease.api.service.web;

import com.alibaba.fastjson.JSONObject;
import com.disease.api.service.config.JwtService;
import com.disease.api.service.entity.BaseUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
public class BaseController {

    @Autowired
    private HttpServletRequest autowiredRequest;

    public String toJsonString(Object obj){
        return JSONObject.toJSONString(obj);
    }

    public BaseUser getBaseUser(){
        String authHeader = autowiredRequest.getHeader("Authorization");
        BaseUser user=JwtService.parseToken(authHeader);
        log.info("用户登录信息{}", toJsonString(user));
        return user;
    }

}
